<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>
    // 单列模式的对象
    // var car1 = {
    //   name: "丰田",
    //   color: "红色",
    //   run: function () { }
    // }
    // var car2 = {
    //   name: "本田",
    //   color: "白色",
    //   run: function () { }
    // }
    // 工厂函数   对象的封装 产生不同的对象
    function car(name, color) {
      var obj = {
        name: name,
        color: color,
        run: function () {
          console.log(obj.name)
        }
      }
      return obj
    }
    var bentian = car("本田", "蓝色");
    var fengtian = car("丰田", "白色")
    var bmw = car("宝马", "红色")
    console.log(bentian)
    console.log(fengtian)
    console.log(bmw)
  </script>
</body>

</html>